package com.concurrent.singleton;

import com.concurrent.annotations.NotThreadSafe;
import com.concurrent.annotations.Recommend;
import com.concurrent.annotations.ThreadSafe;

/**
 * @author: zhouyang
 * @descrpition: 枚举单例模式 JVM保证只被调用一次
 * @time: 2019-05-05 13:19
 */
@ThreadSafe
@Recommend
public class SingletonExample6 {
    //私有构造函数 外面就不能new了
    private SingletonExample6(){
        String str = "";
    }

    public static SingletonExample6 getInstance(){
        return  Singleton.INSTANCE.getInstance();
    }

   private enum Singleton{
        INSTANCE;

        private SingletonExample6 singleton;

        //JVM保证只被调用一次
        Singleton(){
            singleton = new SingletonExample6();
        }

        public SingletonExample6 getInstance(){
            return singleton;
        }
   }
}
